let {middleware, lambda, useNext, useContext} = require('../index');


module.exports = {

    hello(){
        return 'hello world'
    },
    foo2: middleware(lambda(async(a, b)=>{
        console.log(a, b, 'foo2');
        return {sum: a + b}
    })),

    gg: middleware(lambda((param)=>{
        const ctx = useContext();
        // console.log(ctx.path);
        return {msg: `来自${ctx.path}的回复: hello ${param?.name||'匿名'}`}
    })),
    a:{
        b:{
          c(a, b){
             return a + b
          }
        }
    },

    async foo(a, b){
        console.log(a, b)
        return `foo fn: ${a} ${b}.`
    },

    bar: middleware(
        
        async (ctx, next)=>{
            console.log('a');

            ctx.body = 'AAA';
            await next();
        }, 
        async (ctx, next)=>{
            console.log('b')
            await next();
        },
        lambda(async (a, b)=>{
            const next = useNext();
            const ctx = useContext();

            await next();
            ctx.body = 'CCC';
            console.log('c', a, b)

            return {
                a,
                b,
                data:{},
                success: true,
                code: 0,
                msg: `最终返回`
            }
        }),
        async (ctx, next)=>{
            console.log('d', next)
            ctx.body = 'A';
            // await next();
        }
        
    ),


    methodget(...args){
        return { method: 'get', msg: '这是GET请求的返回', args }
    }
}

module.exports.methodget.method = 'get';

// module.exports.foo.method = 'get';
// module.exports.bar.method = 'get';